
  
export default {  
  downloadAndOpenFile:(url) =>{
  	console.log("------进来 JS-------") 
    // return new Promise((resolve, reject) => {  
      const platform = uni.getSystemInfoSync().platform;  
    
      uni.showLoading({  
        title: '加载中...'  
      });  
    
      switch (platform) {  
        case "android":  
          uni.downloadFile({  
            url: url,  
            success: (res) => {  
              uni.hideLoading();  
              const filePath = res.tempFilePath;  
              uni.openDocument({  
                filePath: filePath,  
                showMenu: true,  
                success: function(res) {  
                  console.log('打开文档成功');  
                  resolve();  
                },  
                fail: (err) => {  
                  reject(err);  
                }  
              });  
            },  
            fail: (err) => {  
              reject(err);  
            }  
          });  
          break;  
        case "ios":  
          uni.downloadFile({  
            url: url,  
            success: (res) => {  
              const tempFilePath = res.tempFilePath;  
              uni.getFileSystemManager().saveFile({  
                tempFilePath: tempFilePath,  
                success: (resp) => {  
                  uni.hideLoading();  
                  const savedFilePath = resp.savedFilePath;  
                  uni.openDocument({  
                    filePath: savedFilePath,  
                    fileType: 'pdf',  
                    showMenu: true,  
                    success: () => {  
                      console.log("--打开文档成功---");  
                      resolve();  
                    },  
                    fail: (e) => {  
                      reject('打开文件失败', e);  
                    }  
                  });  
                },  
                fail: (e) => {  
                  reject('保存文件失败', e);  
                }  
              });  
            },  
            fail: (err) => {  
              reject(err);  
            }  
          });  
          break;  
        default:  
          reject('不支持的平台');  
      }  
    // });  
  }  
   
};